export default function (Component) {
    // 返回一个新的 Component 构造器

    return (function (component) {
        // 获取需要hook的方法, 保存方法的原始实现
        const {lifetimes, pageLifetimes} = component;
        /*
        * 生命周期函数 重写
        * */
        if (lifetimes && Object.keys(lifetimes).length > 0) {
            component.lifetimes = (function () {
                let _life = {};
                for (let i in lifetimes) {
                    if (lifetimes[i] && typeof lifetimes[i] === "function") {
                        _life[i] = function () {
                            lifetimes[i].call(component)
                        }
                    }
                }
                return _life
            })()
        }

        /*
        * 页面生命周期重写
        * */
        if (pageLifetimes && Object.keys(pageLifetimes).length > 0) {
            component.pageLifetimes = (function () {
                let _life = {}, that = this;
                for (let i in pageLifetimes) {
                    if (pageLifetimes[i] && typeof pageLifetimes[i] === "function") {
                        _life[i] = function () {
                            pageLifetimes[i].call(that)
                        }
                    }
                }
                return _life
            }) ()
        }



        // 调用原来的构造方法
        return Component(component);
    });
}